package org.kele.sc2020.common.dto;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class KeleResult<T> {

    private int code;
    private String message;
    private T data;

    private static final int RPC_FAIL = 120;

    public static <T> KeleResult<T> success(T data) {
        return new KeleResult<T>().setMessage("success").setCode(0).setData(data);
    }

    public static <T> KeleResult<T> fail(int code, String message) {
        return new KeleResult<T>().setCode(code).setMessage(message);
    }

    public static <T> KeleResult<T> rpcFail() {
        return new KeleResult<T>().setCode(RPC_FAIL).setMessage("call service failed!");
    }

}
